
using System;
using Mono.Data.SqliteClient;

namespace finlasku
{
	public class SQLiteConnectionManager
	{
		private SqliteConnection _connection = null;
		private bool _bConnected = false;
		private string _strConnectionString = null;
		
		public SQLiteConnectionManager(string strConnectionString)
		{
			if (strConnectionString == null)
				throw new ArgumentNullException("strConnectionString");
			
			_strConnectionString = strConnectionString;	
		}
		
		public SqliteConnection OpenConnection()
		{
			if (_connection == null)
				_connection = CreateConnection(_strConnectionString);
			
			if (!_bConnected)
			{
				_connection.Open();
				_bConnected = true;
			}
			
			return _connection;
		}
		
		public void CloseConnection()
		{
			if (_bConnected)
				_connection.Close();	
		}
		
		private SqliteConnection CreateConnection(string strConnectionString)
		{
			SqliteConnection con = new SqliteConnection(strConnectionString);
			
			return con;
		}
	}
}
